﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartSpace.WpfShell.ServiceRef
{
    public partial class DetailData
    {
        public object this[string key]
        {
            get
            {
                foreach (FieldData data in this.Fields)
                {
                    if (data.Name == key)
                    {
                        if (data.Type == "date")
                        {
                            return System.Convert.ToDateTime(data.Value);
                        }
                        else if (string.IsNullOrEmpty(data.Text))
                        {
                            return data.Value;
                        }
                        else
                        {
                            return data.Text;
                        }
                    }
                }
                return string.Empty;
            }
            set
            {
                foreach (FieldData data in this.Fields)
                {
                    if (data.Name == key)
                    {
                        if (data.Type == "date")
                        {
                            data.Value = ((DateTime)value).ToString("yyyy-MM-dd");
                            data.Text = data.Value;
                        }
                        else
                        {
                            data.Value = value.ToString();
                            data.Text = data.Value;
                        }
                        break;
                    }
                }
            }
        }
    }
}
